﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Text.RegularExpressions;
using System.IO;

/// <summary>
/// sessioncontrol の概要の説明です
/// </summary>
public class sessioncontrol
{
    public sessioncontrol()
    {
        //
        // TODO: コンストラクタ ロジックをここに追加します
        //
    }

    public static bool control()
    {   
        try
        {
            StreamReader objReader = new StreamReader(GetRootPath() + "\\time.txt");
            string start = objReader.ReadLine();
            string end = objReader.ReadLine();
            objReader.Close();
            string[] ss = start.Split('=');
            string[] bb = end.Split('=');
            DateTime dt1 = Convert.ToDateTime(ss[1]);
            DateTime dt2 = Convert.ToDateTime(bb[1]);
            DateTime dt3 = Convert.ToDateTime(DateTime.Now.ToString("HH:mm"));
            if (DateTime.Compare(dt3, dt1) >= 0 && DateTime.Compare(dt3, dt2) <= 0)
                return true;
            else
                return false;
        }catch(Exception e2){
            return false;
        }

    }

    public static string controlmessage()
    {
        try
        {
            StreamReader objReader = new StreamReader(GetRootPath() + "\\time.txt");
            string start = objReader.ReadLine();
            string end = objReader.ReadLine();
            objReader.Close();
            string[] ss = start.Split('=');
            string[] bb = end.Split('=');
            DateTime dt1 = Convert.ToDateTime(ss[1]);
            DateTime dt2 = Convert.ToDateTime(bb[1]);
            return dt1.Hour + "時" + dt1.Minute + "分～" + dt2.Hour + "時" + dt2.Minute + "分";
        }
        catch (Exception e2)
        {
            return "";
        }

    }


    public static string GetRootPath()
    {
        string AppPath = "";
        HttpContext HttpCurrent = HttpContext.Current;
        if (HttpCurrent != null)
        {
            AppPath = HttpCurrent.Server.MapPath("~");
        }
        else
        {
            AppPath = AppDomain.CurrentDomain.BaseDirectory;
            if (Regex.Match(AppPath, @"\\$", RegexOptions.Compiled).Success)
                AppPath = AppPath.Substring(0, AppPath.Length - 1);
        }
        return AppPath;
    }
}
